// Spore Switch - when flipped, if user has enough Mechanics skill, sets a flag from 1 to 0 or back
// Cells 0,1 - SDF
// Cell 2 - difficulty
// Cell 3 - special item that activates, if 0 then none
// Cell 4 - can flip back. If 1, can, otherwise not.not used

beginobjectscript; // door lever

variables;

short succeed = 0;

body;

beginstate INIT_STATE;
	if (get_sdf(get_memory_cell(0),get_memory_cell(1)) > 0) 
		set_object_icon(ME,6);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
break;

beginstate USE_STATE;
	if (get_sdf(get_memory_cell(0),get_memory_cell(1)) > 0) {
		print_str_color("Flip Switch: You flip the switch a few times. Nothing happens.",2);
		end();
		}
		
	if (get_memory_cell(3) > 0) {
		if (has_spec_item(get_memory_cell(3)) > 0) {
			print_str_color("Use Key: One of your keys unlocks the switch. You can flip it.",2);
			succeed = 1;
			}
		}
		
	if ((get_stat(21) < get_memory_cell(2)) && (succeed == 0)) {
		print_str("Flip Switch: You don't have enough Mechanics skill to get it ");
		print_big_str("  to work. (Difficulty: ",get_memory_cell(2),")");
		create_text_bubble("Clunk.");
		end();
		}
	print_str_color("Flip Switch: You twist the control. The box makes a faint hissing noise.",2);
	print_str_color("  (Shaped objects nearby may behave differently now.)",2);
	create_text_bubble("Phoosh!");
	play_sound(165);
	
	//if (get_sdf(get_memory_cell(0),get_memory_cell(1)) > 0) {
	//	set_flag(get_memory_cell(0),get_memory_cell(1),0);
	//	set_object_icon(ME,5);
	//	}
	//	else {
			set_flag(get_memory_cell(0),get_memory_cell(1),1);
			set_object_icon(ME,6);
	award_party_xp(BASE_TRAP_XP,trap_lev_to_xp_lev(get_memory_cell(2)));
	//		}
break;

beginstate UNLOCK_STATE;
	print_str_color("Unlock Spell: The spell doesn't affect the spore box.",2);	

break;

//beginstate ITEM_USED_STATE;
//	print_str_color("Use Tool: Using items on a Spore Switch doesn't help.",2);
//break;